from rss_reader import RssReader
from googletrans import Translator


class NewsTranslator:

    def __init__(self):
        self.tr = Translator()
        self.r = RssReader()

    async def feed_translator(self):
        extended_data = []
        feed = await self.r.feed_reader()

        for i in feed:
            # Перевод заголовка
            title = i['title']
            translated_title = self.tr.translate(title, dest='ru')
            ru_title = translated_title.text

            # Перевод статьи
            content = i['content']
            translated_content = self.tr.translate(content, dest='ru')
            ru_content = translated_content.text
            data = {'title': title,
                    'ru_title': ru_title,
                    'content': content,
                    'ru_content': ru_content,
                    'link': i['link'],
                    'pub_date': i['pub_date']}
            extended_data.append(data)

        return extended_data
